#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2024/1/30 17:13
# @Author  : xinyingjie
# @File    : tools.py
# @Description :
from math import radians,sin,cos,asin,sqrt


def calculate_distance(jing1, wei1, jing2, wei2):
    lng1, lat1, lng2, lat2 = map(radians, [jing1, wei1, jing2, wei2])  # 经纬度转换成弧度
    dlon = lng2 - lng1
    dlat = lat2 - lat1
    a = sin(dlat / 2) ** 2 + cos(lat1) * cos(lat2) * sin(dlon / 2) ** 2
    distance = 2 * asin(sqrt(a)) * 6371.393 * 1000  # 地球平均半径，6371.393km

    return distance

